A virtual machine, such as the Java™ Virtual Machine (JVM), may include a garbage collection module (herein referred to as a “garbage collector”) to perform one or more rounds of garbage collection on objects stored in memory during execution of the program containing the object. A round of garbage collection may include operations (herein referred to as “garbage collection operations”) to identify and delete unused objects from a memory space. The memory space is a portion of the memory assigned to the virtual machine. Using the JVM as an example, a Java garbage collector of the JVM may, on behalf of users (such as programmers), manage the allocation of an object to a memory space and the deallocation of the object from the memory space. Each Java object may have a life time in the memory space measured according to how many rounds of garbage collection the Java object has survived. A Java object survives a round of garbage collection if the Java object is not deleted from the memory space. The memory space may be partitioned into multiple regions to store Java objects of different ranges of life time. For example, in a generational garbage collection scheme, the memory space may be partitioned into three regions. The JVM may store Java objects that have been just or recently created in a first region (herein referred to as a “young generation region”). The JVM may copy the Java objects stored in the young generation region after surviving a pre-determined number of rounds of garbage collections to a second region (herein referred to as an “old generation region” or a “tenured generation region”). Further, the JVM may store certain Java objects (such as Java class objects) that are used by the JVM in a third region (herein referred to as a “permanent generation region”). Garbage collections are performed often for Java objects stored in the young generation region, less often for Java objects stored as the old or tenured generation region, and rarely for Java objects stored as the permanent generation region.
The garbage collector of a JVM may automatically perform rounds of generational garbage collection. The Java source code (coded by a user) does not specify how each round of garbage collection is performed. However, in certain situations, the JVM itself cannot accurately determine which Java object is long-lived and which Java object is short-lived, and the default generational garbage collection of JVM may not be optimal for certain Java objects that are known to have a long life.